package java101;

import javax.swing.JOptionPane;

public class LatitudeConverter {

	public static void main(String[] args) {

		String input = JOptionPane.showInputDialog
		("Enter the number of degrees.");
		double latitude = Double.parseDouble(input);
		
		double feedback = minMaxTest(latitude);

		//Degrees test
		int degrees = (int) Math.floor(feedback);
		String degStr = String.format("%d\u00b0",degrees);
		System.out.print(degStr);
		
		//Remove degrees from latitude
		double latMinusDegrees = (double) feedback - degrees;
		
		//Minutes test
		int minutes = (int) Math.floor(latMinusDegrees * 60.);
		System.out.print(minutes + "\"");
		
		//Remove minutes from latMinusDegrees
		double intermediate = minutes / 60.;
		double latMinusMinutes = (double) latMinusDegrees - intermediate;
		
		//Seconds test
		double seconds = (double) (latMinusMinutes * 3600.);
		System.out.println(seconds + "\'");
		
	}

	private static Double minMaxTest(double latitude) {
		
		if (latitude > 90. || latitude < 0.) {
			
			System.out.println("Out of range exception!");
			System.exit(0);
			
		}
		
		else {
			return latitude;
		}
		
		return null;
	}

}
